<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增供应商</title>
<jsp:include page="../../import.jsp" flush="true" />
<style>
#starDt #endDt{
	width : 120px !important;
}
</style>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div id="pageInTab" class="pageInTab">
				<form id="formSet1_splProtocolAdd">
					<div class="fieldset1 tabel_col clearFix">
						<div class="caption">
							<span class="title">资料信息</span>
						</div>
						<div class="fieldBox col_100_auto">
							<div class="label">承诺协议有效期</div>
							<div class="field">
										<input ligerui="width: 180" name="startDt"
											id="startDt" type="text" class="ui-datepicker" value=""
											validate="{required:true}"> - <input
											ligerui="width: 180" name="endDt" id="endDt"
											type="text" class="ui-datepicker" value=""
											validate="{required:true}">
							</div>
						</div>

						<div class="fieldBox col_100">
							<div class="label">附件上传</div>
							<div class="field">
		                           <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload3.jsp" flush="true" >
		                               <jsp:param name="filePath" value="shop/renewProtocol"/>
		                           </jsp:include>
				               <span id="saveBtn" class="sq-button sq-button-round">保存</span>
							</div>
						</div>
					</div>
					
					<div id="ligergridDB" class="sq-grid"></div>
					
					<div class="sqPanel">
						<div class="sqPanel_head inL">
						
						<span>历史记录</span>
							<div class="sqPanel_body">
								<div id="ligergrid_A1" class="sq-grid"></div>
							</div>
						</div>
					</div>
					
					 <div class="btnsBox">
						<span id="saveBtn1" class="sq-button sq-button-round" >提交审核
						</span> 
					</div> 
					   
					
				</form>
		</div>
		</div>
<script type="text/javascript">
<%--=全局变量=--%>
	var splId = ${splId};
	var gridDB = null;
	var oldGridDB = null;
	var dataId = null;
	var pageInApp = {}; // to 下一级子窗口 接口
	var pageInTab = null;
	var loadedTabs = [];
	
	//初始化详情数据
	//initData(); 
	//初始化人员信息
	//initSplRlGrid();
	
	$(function(){
		initGridDB(); //初始化待办列表
		initOldGridDB(); //初始化历史列表
	});
	
	// 添加记录并上传附件
	$('#saveBtn').click(function(){
		//alert();
		var form = new liger.get('formSet1_splProtocolAdd');
		if (!form.valid()) {
			top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
			return;
		}
		var data = form.getData();
		var fileParams = getUploadResultParams(); //获取附件上传的信息
		if (JSON.stringify(fileParams) == "[]") {
			top.$.ligerDialog.SQalert({content: "请先上传附件",SQ_type: "warning"});
			return;
		}
		console.log(fileParams[0].filePath);
        //data["fileParams"] = JSON.stringify(fileParams);
        data["filePath"] = fileParams[0].filePath;
        data["fileNm"] = fileParams[0].fileNm;
		data["splId"] = splId;
		console.log(data);
		$.ajax({
			type : 'post',
			dataType : 'json',
			data : data,
			url : '<%=path%>/spl/splReProtocol/add.do',
			success : function(msg) {
				if (msg.success == 1) {
					console.log(msg);
					gridDB.reload();
				} else {
					$.ligerDialog.SQalert({
						content : msg.info,
						SQ_type : "error"
					});
				}
			}
		});
	});
	
	//初始化列表
	function initGridDB() {
		$("#ligergridDB").ligerGrid({
			url : '<%=path%>/spl/splReProtocol/initList.do?splId=' + splId + '&isNew=2',
			method : 'get',
			columns : [
				{
					display : '承诺协议有效期',
					name : '',
					width : 200,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						//return rowdata.protocolStartTm + '-' + rowdata.protocolEndTm ;
						return renderDate(rowdata.protocolStartTm)
								+ '-' +
								renderDate(rowdata.protocolEndTm);
					}
				},
				{
					display : '上传文件名',
					name : 'fileNm',
					minWidth : 100,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						var a = '<a href="javascript:showAttachment(\''+rowdata.filePath+'\')">' + rowdata.fileNm +'</a>';
						return a ;
					}
				},
				{
					display : '上传者',
					name : 'crtUsrNm',
					minWidth : 100,
					enabledSort : false
				},
				{
					display : '上传时间',
					name : 'crtTm',
					minWidth : 150,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						if (value){
							return renderDate(value);
						}
					}
				},
				{
					display : '生效时间',
					name : 'effectiveTm',
					minWidth : 100,
					enabledSort : false
				},
			],
			pageSize : 10,
			pageSizeOptions : [ 10, 20, 30, 40, 50, 100 ], //按照自己的喜好选择不同的页面显示条数
			root : 'rows',
			record : 'total',
			hideLoadButton : true,
			width : '100%',
			height : '40%',
			//heightDiff : -30,
			//checkbox : true,
			rownumbers : true,
			onAfterShowData : function() {
				$(".gridTip").grid_ligerTip();
				SetIframe_height();
			},
			onLoaded : function (grid) {
				console.log(grid);
				grid.toggleLoading(null);
				if (grid.data.rows[0].id) {
					console.log(grid.data.rows[0].id);
					dataId = grid.data.rows[0].id
				}
			}
		});
		gridDB = liger.get("ligergridDB");
		gridDB.setHeight(100);
		gridDB.options.isSingleCheck = true;
	}
	
	//展示附件
	function showAttachment(path){
		if (!path)return;
		window.open(path);
	}
	
	//初始化历史列表
	function initOldGridDB() {
		$("#ligergrid_A1").ligerGrid({
			url : '<%=path%>/spl/splReProtocol/initList.do?splId=' + splId + '&isNew=1',
			method : 'get',
			columns : [
				{
					display : '承诺协议有效期',
					name : '',
					width : 200,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						//return rowdata.protocolStartTm + '-' + rowdata.protocolEndTm ;
						return renderDate(rowdata.protocolStartTm)
								+ '-' +
								renderDate(rowdata.protocolEndTm);
					}
				},
				{
					display : '上传文件名',
					name : 'fileNM',
					minWidth : 100,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						var a = '<a href="javascript:showAttachment(\''+rowdata.filePath+'\')">' + rowdata.fileNm +'</a>';
						return a ;
					}
				},
				{
					display : '上传者',
					name : 'crtUsrNm',
					minWidth : 100,
					enabledSort : false
				},
				{
					display : '上传时间',
					name : 'crtTm',
					minWidth : 150,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						if (value){
							return renderDate(value);
						}
					}
				},
				{
					display : '生效时间',
					name : 'effectiveTm',
					minWidth : 100,
					enabledSort : false
				},
			],
			pageSize : 10,
			pageSizeOptions : [ 10, 20, 30, 40, 50, 100 ], //按照自己的喜好选择不同的页面显示条数
			root : 'rows',
			record : 'total',
			hideLoadButton : true,
			width : '100%',
			height : '65%',
			//heightDiff : -30,
			//checkbox : true,
			rownumbers : true,
			onAfterShowData : function() {
				$(".gridTip").grid_ligerTip();
				SetIframe_height();
			},
			onLoaded : function (grid) {
				//console.log(grid);
				grid.toggleLoading(null);
				//console.log(grid.data.row);
			}
		});
		oldGridDB = liger.get("ligergrid_A1");
		oldGridDB.setHeight(100);
		oldGridDB.options.isSingleCheck = true;
	}
	
	$('#saveBtn1').click(function(){
		//alert();
		var wait_dialog;
		$.ajax({
			type : 'post',
			dataType : 'json',
			//data : data,
			url : '<%=path%>/spl/splReProtocol/addRenewProtocolFlow.do?id=' + dataId,
			beforeSend : function() {
				wait_dialog = $.ligerDialog.SQalert({
					content : '正在提交...',
					SQ_type : "waitting"
				});
			},
			success : function(msg) {
				wait_dialog.close();
				if (msg.success == 1) {
					$.ligerDialog.SQalert({
						content : '流程发起成功',
						SQ_type : "success"
					});
				} else {
					$.ligerDialog.SQalert({
						content : msg.info,
						SQ_type : "error"
					});
				}
			}
		});
	})
	
	var formSet1 = $('#formSet1_splProtocolAdd').ligerForm({
        validate : true
	});
	
	//格式化时间
	function renderDate(value) {
		var dateStr = "";
		if (null != value) {
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, "yyyy-MM-dd hh:mm");
		}
		return dateStr;
	}


//初始化Tab页
		function initTab() {
			pageInTab = $("#pageInTab").ligerTab({
				height : 'auto',
				contextmenu : false,
				minIframeHeight : GET_minIframeHeight(),
				onAfterSelectTabItem : function(tabid) {
					currTab = tabid; //赋值是哪个Tab页面
					if (loadedTabs.indexOf(tabid) < 0) {
						loadedTabs.push(tabid);
						switch (tabid) {
						case "tabB":
							pageInTab.setTabItemSrc(tabid, "<%=path%>/bizflow/rskUsrAchLog/toMyAchievementsPage.do");
							break;
						}
					}
					;
					SetIframe_height();
				}
			});
	
			$.extend(true, pageInApp, {
				pageInTab : pageInTab
			});
		}

<%-- jquery==end--%>
</script>
</body>
</html>
